package com.inspur.ourhis_afterend.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Dao.DoctorsDao;
import com.inspur.ourhis_afterend.Entity.Dept;
import com.inspur.ourhis_afterend.Entity.Doctors;
import com.inspur.ourhis_afterend.Service.DoctorsService;
import com.inspur.ourhis_afterend.Tools.PageAction;
import com.inspur.ourhis_afterend.model.Doctor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("doctorService")
public class DoctorsServiceImpl implements DoctorsService {

    @Autowired
    DoctorsDao doctorsDao;

    @Override
    public IPage<Doctors> findAll(PageAction pageAction) throws Exception {
        IPage<Doctors> iPage = new Page<>(pageAction.getPageNo(), pageAction.getPageSize());
        return doctorsDao.selectPage(iPage, null);
    }

    @Override
    public List<Doctors> search(String departId, String realName, String docId) throws Exception {
        QueryWrapper<Doctors> queryWrapper = new QueryWrapper<>();
        if (docId != null) {
            queryWrapper.eq("docid", docId);
            return doctorsDao.selectList(queryWrapper);
        } else if (realName != null) {
            queryWrapper.like("realname", realName);
            return doctorsDao.selectList(queryWrapper);
        } else if (departId != null) {
            queryWrapper.eq("departid", departId);
            return doctorsDao.selectList(queryWrapper);
        }else {
            return null;
        }
    }

    @Override
    public int add(Doctors doctors) throws Exception {
        return doctorsDao.insert(doctors);
    }

    @Override
    public int edit(Doctors doctors) throws Exception {
        return doctorsDao.updateById(doctors);
    }

    @Override
    public int del(String docId) throws Exception {
        return doctorsDao.deleteById(docId);
    }

    @Override
    public Doctors findOne(String docId) throws Exception {
        return doctorsDao.selectById(docId);
    }
}
